package com.zxm.web.controller.tool;

import com.zxm.common.core.controller.BaseController;
import com.zxm.common.core.domain.AjaxResult;
import com.zxm.common.utils.sign.HMACSHA1;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.bind.DatatypeConverter;

/**
 * 去邮箱控制器
 *
 * @author zxm
 */
@RestController
@RequestMapping("/tool/toMail")
public class ToMailController extends BaseController {
	private static final String ENCRYPTKEY = "5fa036fdb65d3828d8b772bc4c88db44a945a413f016c0ce51d8fe6ed1e4713d";

	@PreAuthorize("@ss.hasPermi('tool:mail:view')")
	@GetMapping()
	public AjaxResult index(String email) throws Exception {
		String timestamp = String.valueOf(System.currentTimeMillis());
		System.out.println(timestamp);

		System.out.println(email);
		byte[] bytes = HMACSHA1.HmacSHA1Encrypt(email + "|name|0|" + timestamp, ENCRYPTKEY);
		String preauth = DatatypeConverter.printHexBinary(bytes);
		System.out.println(preauth);
		return AjaxResult.success("链接获取成功！","https://mail.jxthxr.com/service/preauth?account="+email+"&by=name&expires=0&timestamp="+timestamp+"&preauth="+preauth);
	}
}
